/*
 * threadpool.h
 *
 *  Created on: 2012-5-2
 *      Author: epmm
 */

#ifndef THREADPOOL_H_
#define THREADPOOL_H_

class CThreadPool
{
public:

private:

	bool m_Block;

	u_int m_nWorkThreadNum;
	u_int m_NoBlockSleep;

 	CWorkTask m_WorkTask; //任务队列对象

	CThreadCondition m_CreateThreadCond; //工作线程创建条件变量
	CThreadMutex m_CreateThreadMtx; //工作线程条件创建变量锁

public:
	CThreadPool();
	CThreadPool(int threadnum,bool block,int max_queue);
	virtual ~CThreadPool();

public:
	void Init();
	int AddTask(CJobBase* pJob);
	void CreateWorkThreadSync(int nNum);
	void CreateWorkThread(int nNum);
	void CreateDispatchThread();
	void DispatchProcess();
	void SetNoBlockSleep(unsigned int nSleep);

	CJobBase* getJob();

	void GetAllThreadCnt();
	void GetBusiThreadCnt();

	static void* startDispatchMain(void* pParam);

	friend class CWorkThread;
};

#endif /* THREADPOOL_H_ */
